package com.czr.util;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.http.HttpMethodName;
import com.qcloud.cos.region.Region;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URL;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class TencentCosUtil {
    String secretId="AKIDMckfsKfkx6X5HOVUNcmldXEhBSUGo7B1";
    String secretKey="e8PSFBsOhmdJm36uWv53pMgmeJn9LJ2X";
    String regionId="ap-nanjing";
    String bucketName="czr-1318160625";
    public  String imgFile_wx(String fileName) throws Exception {

//        COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
//        Region region = new Region(regionId);
//        ClientConfig clientConfig = new ClientConfig(region);
//        COSClient cosClient = new COSClient(cred, clientConfig);
//        Date expirationDate = new Date(System.currentTimeMillis() + 30 * 60 * 1000);
//        Map<String, String> params = new HashMap<String, String>();
//        params.put("fileName", fileName);
//        Map<String, String> headers = new HashMap<String, String>();
//        HttpMethodName method = HttpMethodName.GET;
//
//        URL url = cosClient.generatePresignedUrl(bucketName, fileName, expirationDate, method, headers, params);
//        cosClient.shutdown();
        String url="";
//        if(!StringUtils.isEmpty(fileName) && !fileName.contains("https")){
//            url="https://czr-bj-1318160625.cos.ap-beijing.myqcloud.com/"+fileName+"/czr_ys";
//        }else if (!StringUtils.isEmpty(fileName) && fileName.contains("http")){
//            url=fileName;
//        }
        url=fileName;
        return url;
    }
}
